package io.wongxd.demo.page

import androidx.compose.foundation.gestures.Orientation
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.statusBars
import androidx.compose.foundation.layout.statusBarsPadding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import io.wongxd.solution.baseView.BaseComposeFragment
import io.wongxd.solution.compose.composeTheme.AppThemeHolder
import io.wongxd.solution.compose.composeTheme.appColor
import io.wongxd.solution.compose.composeTheme.textStyle
import io.wongxd.solution.compose.custom.Typewriter
import io.wongxd.solution.logger.Logger
import io.wongxd.solution.network.NetworkObserver
import io.wongxd.solution.network.NetworkStateObserver

class FgtTrans : BaseComposeFragment() {
    override fun lazyInit() {

    }

    @Composable
    override fun Render() {
        Column(
            Modifier
                .fillMaxSize()
                .verticalScroll(rememberScrollState()),
            horizontalAlignment = Alignment.CenterHorizontally
        ) {

            val dens = LocalDensity.current
            val statusBarsHeight = WindowInsets.statusBars.getTop(dens)
            val des = "状态栏高度:${statusBarsHeight}  FgtTrans"
            Logger.d(des)
            Text(text = des, modifier = Modifier.statusBarsPadding())


            val netState = remember {
                NetworkStateObserver.Builder()
                    .activity(requireActivity())
                    .build()
                    .callNetworkConnectionFlow()
                    .observe()
            }

            val networkInfo = netState.collectAsState(initial = NetworkObserver.Status.Unavailable).value

            Text(
                text = "网络:${networkInfo}",
                style = AppThemeHolder.textStyle.sp16.appColor(),
                modifier = Modifier.padding(20.dp)
            )

            Button(
                onClick = {
                    atySupportBack()
                }, modifier = Modifier
                    .padding(top = 80.dp)
            ) {
                Text(text = "返回")
            }

            val animatePartsList = remember {
                "山不在高,有仙则名.水不在深,有龙则灵."
            }

            Typewriter(
                "小时候叔叔对我说:", animatePartsList, Orientation.Vertical
            )

        }
    }

    @Preview(showBackground = true, backgroundColor = 0xffffffff)
    @Composable
    fun RenderPreView() {

    }
}